package com.ecr.hub.front.validator;

import javax.faces.application.FacesMessage;
import javax.faces.application.FacesMessage.Severity;
import javax.faces.component.UIComponent;
import javax.faces.context.FacesContext;

public class LengthValidator extends AbstractGenericValidator {

	@Override
	protected boolean executeValidator(FacesContext arg0, UIComponent arg1,
			Object arg2) throws Exception {
		
		int minLength = Integer.parseInt(arg1.getAttributes()
				.get("minLength").toString());
		
		return (arg2.toString().length() > minLength);
	}

	@Override
	protected String[] getAttributsList() {
		return new String[]{AbstractValidator.FIELD_NAME, "minLength"};
	}

	@Override
	protected String getMessageKey() {
		return "validator.length";
	}

	@Override
	protected Severity getSeverityLevel() {
		return FacesMessage.SEVERITY_ERROR;
	}
}
